package cn.zut.edu.business;

import cn.zut.edu.dao.StudentDao;
import cn.zut.edu.model.Student;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

@Service
public class ScoreService {

    private StudentDao studentDao;

    public void insertStudent(Student student){
        studentDao.insertStudent(student);
    }

    public List<Student> showAllStudent(){
        return studentDao.queryAll();
    }

    public int number(){
        return studentDao.queryAll().size();
    }

    public double averageScore(){

        double sum=0;
        List<Student> students=studentDao.queryAll();
        for(Student student:students){
            sum=sum+student.getScore();
        }
        int n=students.size();
        return sum/n;
    }




    @Autowired
    @Qualifier(value = "bdi1")
    public void setStudentDao(StudentDao studentDao) {
        this.studentDao = studentDao;
    }
}
